import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

axios.defaults.baseURL = 'http://localhost/api.php'

Vue.use(Vuex)

const store = new Vuex.Store({
    state:{
        lists:[],
        pageConfige:{
            currentPage:1,
            pageSize:9
        },
        arrAll:[],
         len:10,
         count:0,
         arr:[],
         total:0,
         listsCol:[]
    },
    mutations:{
        getlistLen(state,num){
            state.total = num
        },
        getList(state,arr){
            state.lists =arr
         },
         getColList(state,arr){
            state.listsCol =arr
         },
    },
    actions:{
        getListData({commit,state},num){
           return  axios.get('http://localhost/api.php/sendout',{
                params:{
                    transform:1,
                    order:'id,desc',
                    page:num+','+9
                }
            })
            .then( res =>{
                commit('getlistLen',res.data._results)
                commit('getList',res.data.sendout)
                // return 
            })
        },
        updateList({commit},obj){
            return axios.put('http://localhost/api.php/sendout/'+obj.id,{status:obj.status})
                .then( res=>{
                    console.log(res.data)
                })
        },
        getCollectList({commit}){
            return  axios.get('http://localhost/api.php/sendout',{
                params:{
                    transform:1
                }
            })
            .then( res =>{
                commit('getColList',res.data.sendout) 
            })
        },
    },
    getters:{
        getCollect: state =>{
            // return  state.lists.filter(
            //     item =>item.status
            // )
            // state.lists 初始情况下没值 所以得到值为空
            // return  state.lists.find(
            //     item =>item.status
            // )
        }

    }
})
export default store